package org.deschutter.scans.jumpgate;

import org.deschutter.scans.Scan;
import org.deschutter.constants.Config;
import org.deschutter.exceptions.AddJGPLineException;
import org.deschutter.exceptions.DeriveIntelException;
import org.deschutter.hibernate.JumpgateProbeType;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import java.math.BigDecimal;
import java.util.Date;

/**
 * User: Berten De Schutter
 * Date: 02-Jul-2009
 * Time: 17:07:20
 */
public class Fleet implements Comparable {
    private String x, y, z;
    private Integer eta, amount;
    private String race;
    private String fleetname;
    private Scan scan;

    Fleet(String x, String y, String z, Integer eta, Integer amount, String fleetname, Scan scan) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.eta = eta;
        this.amount = amount;
        this.fleetname = fleetname;
        this.scan = scan;
    }

    public void deriveIntel() throws DeriveIntelException {
        // Override this method
    }

    public org.deschutter.hibernate.Jumpgate getJGP() throws AddJGPLineException {
        org.deschutter.hibernate.Jumpgate jgp = new org.deschutter.hibernate.Jumpgate();
        jgp.setJumpgateProbeTypeByTypeId(getJGPType());
        jgp.setScansByScanId(scan.getHbscan());
        jgp.setX(getX());
        jgp.setY(getY());
        jgp.setZ(getZ());
        jgp.setEta(getEta());
        jgp.setAmount(getAmount());
        jgp.setFleetName(getFleetname());
        Date date = new Date();
        String key = scan.getID() + getAmount() + getFleetname() + date.hashCode();
        jgp.setId(key.hashCode());
        System.out.println(jgp.toString());
       return jgp;
        //Queries.getJGP(scanId, getFleetType(), getX(), getY(), getZ(), getEta(), getAmount(), getFleetname());
    }

    Integer getEta() {
        return eta;
    }

    public void setEta(Integer eta) {
        this.eta = eta;
    }

    Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public String getRace() {
        return race;
    }

    public void setRace(String race) {
        this.race = race;
    }

    String getFleetname() {
        return fleetname;
    }

    public void setFleetname(String fleetname) {
        this.fleetname = fleetname;
    }

    public int compareTo(Object o) {
        if (this.eta < ((Fleet) o).eta) {
            return 0;
        } else {
            return 1;
        }
    }

    String getX() {
        return x;
    }

    public void setX(String x) {
        this.x = x;
    }

    String getY() {
        return y;
    }

    public void setY(String y) {
        this.y = y;
    }

    String getZ() {
        return z;
    }

    public void setZ(String z) {
        this.z = z;
    }

    public BigDecimal getFleetType() {
        return Config.BIGDECIMAL_ZERO;
    }

    public Scan getScan() {
        return scan;
    }

    public void setScan(Scan scan) {
        this.scan = scan;
    }

    public JumpgateProbeType getJGPType() {
        JumpgateProbeType jgptype = new JumpgateProbeType();
        Criteria crit = scan.getSession().createCriteria(JumpgateProbeType.class).add(Restrictions.eq("id", getFleetType()));
        for (Object typ : crit.list()) {
            jgptype = (JumpgateProbeType) typ;
        }
        return jgptype;
    }
}
